<?php
namespace Mobile\Controller;

class NotifyController extends MobileController {
    /**
    * 获取系统通知列表
    * 
    */
    public function index($p=1){
        $category = $this->category();
        $Document = D('Document');
        $count = $Document->listCount($category['id']);
        $list = $Document->page($p, $category['list_row'])->lists($category['id'],'`id` DESC',1,'id,title,description,cover_id,create_time');
        foreach($list as &$row){
            if($row['cover_id']>0){
                $row['picurl'] = $this->getFullUrl(get_cover($row['cover_id'],'path'));
            }else{
                $row['picurl'] = '';
            }
            unset($row['cover_id']);
            $row['content'] = U('Detail/index',array('id'=>$row['id']),true,true);
        }
        $ret = array(
            'count' => $count,
            'data' => $list,
        );
        $this->succ($ret);
    }    
    
    private function category(){
        /* 获取分类信息 */
        $category = D('Category')->info('system_notify');
        if($category && 1 == $category['status']){
            switch ($category['display']) {
                case 0:
                    $this->err('该分类禁止显示！');
                    break;
                //TODO: 更多分类显示状态判断
                default:
                    return $category;
            }
        } else {
            $this->err('分类不存在或被禁用！');
        }
    }
}